package cn.t.web.order;

import cn.t.core.mode.PageInfoDTO;
import cn.t.core.mode.PageQueryDTO;
import cn.t.facade.order.WorkOrderFacade;
import cn.t.listener.CustomCellWriteWidthConfig;
import cn.t.model.order.WorkOrderDetailDO;
import cn.t.request.WorkOrderReq;
import cn.t.vo.order.WorkOrderVO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * 工单管理
 *
 * @author t
 * @since 2024-05-24 10:15:14
 */
@Slf4j
@RestController
@RequestMapping("workOrder")

@AllArgsConstructor
public class WorkOrderController {

    private final WorkOrderFacade workOrderFacade;

    /**
     * 工单分页列表
     */
    @PostMapping("/page")
    public PageInfoDTO<WorkOrderVO> page(@RequestBody PageQueryDTO<WorkOrderReq> req) {
        return this.workOrderFacade.page(req);
    }

    /**
     * 导出工单
     */
    @PostMapping("/export")
    public void export(@RequestBody WorkOrderReq request, HttpServletResponse response) {
        this.workOrderFacade.export(request, response, new CustomCellWriteWidthConfig());
    }

    /**
     * 工单详情分页列表
     */
    @PostMapping("/detailPage")
    public PageInfoDTO<WorkOrderDetailDO> detailPage(@RequestBody PageQueryDTO<WorkOrderDetailDO> req) {
        return this.workOrderFacade.detailPage(req);
    }
}

